<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <button>获取电影</button>
    <button>获取学员</button>
    <button>添加学员</button>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');

        // 设置axios的默认全局配置
        // 可以加任意配置项
        axios.defaults.method = "get";
        // baseURL 根路径
        axios.defaults.baseURL = 'http://api.zhibao.com:3000';

        //获取电影
        btns[0].onclick = async function(){
           let {data} = await axios('/movies');
           console.log(data);
        }

        //获取学员
        btns[1].onclick = async function(){
            let {data} = await axios.get('/students');
            console.log(data);
        }

        // 添加学员
        btns[2].onclick = function(){
            // axios.post('/students',{
            //     name:"老李",
            //     age:88,
            //     score:18
            // });

            axios('http://api.zhibao.com:3000/students',{
                method:"post",
                data:{
                    name:"光头强",
                    age:99,
                    score:99
                }
            });


        }
    
       
    </script>
</body>

</html>